package com.jiangruan.javaproject.service;

import com.alibaba.fastjson.JSONObject;
import com.jiangruan.javaproject.Constants;
import com.jiangruan.javaproject.bean.*;
import com.jiangruan.javaproject.request.HttpUtils;

import java.util.List;
import java.util.Scanner;

/**
 * @author:huayuzhuo
 * @email:2798866329@qq.com
 * @desc:  该类封装程序各功能
 * @datatime: 2021/12/15 16:06
 */
public class HotVideoService {

    public static List<HotVideo> getHotVideo(){
        System.out.println("开始查询热门视频");
        //url路径是：url+key+type可选travel_overall(整体的)、travel_new(新的)+size(每次请求数据的条数)
        String url = Constants.TRIP_URL + "?key=" + Constants.TRIP_KEY + "&type=hot_video" + "&size=20";

        String resule = HttpUtils.get(url);

        HotVideoCommon videoCommon = JSONObject.parseObject(resule, HotVideoCommon.class);

        return videoCommon.result;
    }

    public static List<TianQVideo> getTianq(){
        System.out.println("开始查询城市天气");
        //url路径是url+city+key
        System.out.println("请输入要查询的城市");
        Scanner kp = new Scanner(System.in);
        String rt = kp.next();
        String url = Constants.TIAN_URL + "?city=" + rt + "&key=" + Constants.TIAN_KEY;

        String resule = HttpUtils.get(url);

        TianQVideoCommom tianQVideoCommom = JSONObject.parseObject(resule, TianQVideoCommom.class);

        return tianQVideoCommom.result;

    }

    public static List<XingZuoPueksR> getXing(){
        System.out.println("开始查询星座");
        //url路径是url+key+keyword
        System.out.println("请输入您的出生日期或星座:");
        Scanner kp = new Scanner(System.in);
        String rt = kp.next();

        String url = Constants.XING_URL + "?key=" + Constants.XING_KEY + "&keyword=" + rt;
        String result = HttpUtils.get(url);

        XingZuoPueks xingZuoPueks = JSONObject.parseObject(result,XingZuoPueks.class);
        return xingZuoPueks.result;
    }

    public static List<XingZuoPksR> getXingP(){
        System.out.println("开始查询星座配对");
        //url:url + ?key= + &men= 男生星座 &women= 女生星座
        Scanner kp = new Scanner(System.in);
        System.out.println("请输入您的性别：");
        String rt = kp.next();
        System.out.println("请输入您的星座：");
        String rt2 = kp.next();
        System.out.println("请输入您想配对的星座：");
        String rt3 = kp.next();

        String url = Constants.XINGPD_URL + "?key=" + Constants.XINGPD_KEY + "&men=" + rt2 + "&women=" + rt3;
        String url2 = Constants.XINGPD_URL + "?key=" + Constants.XINGPD_KEY + "&men=" + rt3 + "&women=" + rt2;
        if (rt.equals("男")){
            String s = HttpUtils.get(url);
            XingZuoPks xingZuoPks = JSONObject.parseObject(s,XingZuoPks.class);
            return xingZuoPks.getResult();
        } else if (rt.equals("女")){
            String s2 = HttpUtils.get(url2);
            XingZuoPks xingZuoPks = JSONObject.parseObject(s2,XingZuoPks.class);
            return xingZuoPks.getResult();
        } else {
            System.out.println("请重新输入男或女性别");
        }
        return null;
    }
}
